import Vue from "vue";
// 不含icon提示框
const message = str => {
  return new Promise((resolve, reject) => {
    uni.showToast({
      title: str,
      icon: "none",
      duration: 2000,
      success: () => {
        setTimeout(() => {
          resolve;
        }, 1000);
      },
    });
  });
};
// 成功提示框
const successMessage = str => {
  return new Promise((resolve, reject) => {
    uni.showToast({
      title: str,
      icon: "success",
      duration: 2000,
      success: () => {
        setTimeout(() => {
          resolve();
        }, 1000);
      },
    });
  });
};
// loading
const showLoading = title => {
  return new Promise((resolve, reject) => {
    uni.showLoading({
      success: () => {
        resolve();
      },
      fail: err => {
        reject(err);
      },
    });
  });
};
// tipLoading ==>提示loading
const tipLoading = str => {
  return new Promise((resolve, reject) => {
    uni.showLoading({
      title: str,
      mask: true,
      success: () => {
        resolve();
      },
      fail: err => {
        reject(err);
      },
    });
  });
};
// 隐藏loading
const hideLoading = () => {
  return new Promise((resolve, reject) => {
    uni.hideLoading({
      success: () => {
        resolve();
      },
    });
  });
};
Vue.prototype.$layer = {
  message: message,
  successMessage: successMessage,
  showLoading: showLoading,
  tipLoading: tipLoading,
  hideLoading: hideLoading,
};